<?php

namespace app\common\lib\exception;

use Exception;
use think\exception\Handle;

class ExceptionHandler extends Handle
{
    protected $code;
    protected $msg;
    public function render(Exception $e)
    {
        if ($e instanceof BaseException) {
            $this->code = $e->code;
            $this->msg = $e->msg;

        }else{
            // 如果在调试模式下，需展示thinkphp5.0默认异常提示
            if(config('app_debug')){
                return parent::render($e);
            }
            $this->code = 500;
            $this->msg = '服务器内部错误';
        }

        $result = [
            'msg' => $this->msg,
            'code' => $this->code,
        ];

        return json($result);
    }

}